<template>
  <div class="list-container">
    <div class="search-wrap clearfix">
      <div class="search-wrap-conditions fl">
        <el-select
          v-model="listQuery.condition.certType"
          clearable
          placeholder="选择证书类型"
          @change="resetPage"
        >
          <el-option
            v-for="item in optionsCert"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <div class="search-wrap-conditions fl marginL10">
        <el-input
          v-model="listQuery.condition.keyword"
          class="input-width"
          placeholder="关键词, 报名人"
          @keyup.enter.native="resetPage"
        />
      </div>
      <div class="search-wrap-btn fr">
        <el-button :disabled="loading" @click="resetSearch">重置</el-button>
        <el-button :disabled="loading" type="primary" @click="resetPage">搜索</el-button>
        <!-- <el-button :disabled="loading" type="success" @click="exportContent">导出</el-button> -->
      </div>
    </div>
    <div class="main-wrapper">
      <custom-table :data="listData" :columns="columns">
        <!-- <template slot-scope="{ row }">
          <el-button type="text" @click="refund(row)">退款</el-button>
        </template>-->
      </custom-table>
      <pagination :total="total" :page="listQuery.pager.page" @pagination="pagination" />
    </div>
  </div>
</template>

<script>
import CustomTable from '@/components/CustomTable/index';
import Pagination from '@/components/Pagination/index';
import { optionsCert } from './mock.js';
import { getCertList } from '@/api/apply';

export default {
  name: 'List',
  components: {
    CustomTable,
    Pagination
  },
  data () {
    return {
      loading: false,
      optionsCert: optionsCert,
      listQuery: {
        condition: {
          certType: null,
          keyword: null
        },
        pager: {
          page: 1,
          pageSize: 10
        }
      },
      listData: [],
      total: 0,
      columns: [
        { label: '序号', value: 'index', align: 'center', width: '80px' },
        { label: '报名项目', align: 'center', value: 'certType' },
        { label: '订单号', align: 'center', value: 'orderId', width: '400px' },
        { label: '报名人', align: 'center', value: 'name' },
        { label: '用户来源', align: 'center', value: 'source' },
        { label: '支付状态', align: 'center', value: 'payStatus' }
        // { label: '操作', align: 'center', value: 'todo' }
      ]
    };
  },
  created () {
    this.init();
  },
  methods: {
    resetPage () {
      this.listQuery.pager.page = 1;
      this.listQuery.pager.pageSize = 10;
      this.init();
    },
    init () {
      this.loading = true;
      this.listQuery.condition.keyword = this.listQuery.condition.keyword ? this.listQuery.condition.keyword : null;
      getCertList(this.listQuery)
        .then(res => {
          console.log(res);
          this.listData = res.data.records;
          this.total = res.data.total;
          this.loading = res.loading;
          // console.log(res)
        })
        .catch(error => {
          this.loading = false;
        });
    },
    resetSearch () {
      this.listQuery = {
        condition: {
          // certType: this.optionsCert[0].value,
          certType: '',
          keyword: null
        },
        orderBys: [
          {
            asc: true,
            column: null
          }
        ],
        pager: {
          page: 1,
          pageSize: 10
        }
      };
      this.init();
    },
    pagination ({ page, limit }) {
      this.listQuery.pager.page = page;
      this.listQuery.pager.pageSize = limit;
      this.init();
    },

    refund (rows) {
      console.log(rows);
    },
    exportContent () {
      console.log('导出数据');
    }
  }
};
</script>

<style lang="scss" scoped></style>
